home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
edit
/
ae_14.zip
/
AE2.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1991-02-27
|
17KB
|
462 lines
unit AE2 ;
{$B-}
{$I-}
{$S+}
{$V-}
{-----------------------------------------------------------------------------}
{ This unit contains all movement procedures. }
{ All procedures operate on the current workspace (indicated by CurrentWsnr), }
{ unless specified otherwise. }
{-----------------------------------------------------------------------------}
interface
uses Crt,Dos,AE0,AE1 ;
procedure Home (var P:Position) ;
procedure EndOfLine (var P:Position) ;
procedure CalculateColnr (var P:position) ;
procedure SkipDown (var P:Position ; Distance:word) ;
procedure SkipUp (var P:Position ; Distance:word) ;
procedure WordDown (var P:Position) ;
procedure WordUp (var P:Position) ;
procedure LineDown (var P:Position) ;
procedure LineUp (var P:Position) ;
procedure SearchUp (Target:string ; var P:Position ; LimitIndex:word) ;
procedure SearchDown (Target:string ; var P:Position ; LimitIndex:word) ;
procedure SearchString (Target:string ; var P:Position) ;
procedure MatchBracketsDown (OpenBracket,CloseBracket:char ; var P:Position) ;
procedure MatchBracketsUp (OpenBracket,CloseBracket:char ; var P:Position) ;
implementation
{-----------------------------------------------------------------------------}
{ Sets P to the first column of the line it is pointing to }
{-----------------------------------------------------------------------------}
procedure Home (var P:Position) ;
begin
Dec (P.Index,P.Colnr-1) ;
P.Colnr := 1 ;
end ;
{-----------------------------------------------------------------------------}
{ Sets P to the last column of the line it is pointing to (CR or end of file) }
{-----------------------------------------------------------------------------}
procedure EndOfLine (var P:Position) ;
begin
with Workspace[CurrentWsnr] do
begin
while (Buffer^[P.Index] <> CR) and
(P.Index < Buffersize) do
begin
Inc (P.Index) ;
Inc (P.Colnr) ;
end ;
end ; { of with }
end ;
{-----------------------------------------------------------------------------}
{ Re-calculates the column number by searching for a previous line feed }
{-----------------------------------------------------------------------------}
procedure CalculateColnr (var P:position) ;
begin
with Workspace[CurrentWsnr] do
begin
if P.Linenr = 1
then P.Colnr := P.Index
else begin
P.Colnr := 1 ;
while (Buffer^[P.Index-P.Colnr] <> CR) do Inc (P.Colnr) ;
if Buffer^[P.Index-P.Colnr+1] = LF
then Dec (P.Colnr) ;
end ;
end ;
end ;
{-----------------------------------------------------------------------------}
{ Skips P <Distance> positions downward, adjusting line and column number. }
{ If the end of the buffer is reached, the procedure stops. }
{-----------------------------------------------------------------------------}
procedure SkipDown (var P:Position ; Distance:word) ;
var Counter : word ;
begin
with Workspace[CurrentWsnr] do
begin
for Counter := 1 to Distance do
begin
if P.Index = BufferSize then Exit ;
if Buffer^[P.Index] = CR
then begin
Inc (P.Linenr) ;
if Buffer^[P.Index+1] = LF
then P.Colnr := 0
else P.Colnr := 1 ;
end
else Inc (P.Colnr) ;
Inc (P.Index) ;
end ;
end ;
end ;
{-----------------------------------------------------------------------------}
{ Skips P <Distance> positions upward, adjusting line and column number. }
{ If the start of the buffer is reached, the procedure stops. }
{-----------------------------------------------------------------------------}
procedure SkipUp (var P:Position ; Distance:word) ;
var Counter : word ;
begin
with Workspace[CurrentWsnr] do
begin
if Distance < P.Colnr
then begin
{ P will remain within current line }
Dec (P.Colnr,Distance) ;
Dec (P.Index,Distance) ;
end
else begin
if P.Index <= Distance
then begin
{ go to start of buffer }
P.Index := 1 ;
P.Colnr := 1 ;
Exit ;
end ;
for Counter := 1 to Distance do
begin
Dec (P.Index) ;
if Buffer^[P.Index] = CR
then Dec (P.Linenr) ;
end ;
CalculateColnr (P) ;
end ;
end ;
end ;
{-----------------------------------------------------------------------------}
{ Skips P downward until the beginning of the next word in the text. }
{-----------------------------------------------------------------------------}
procedure WordDown (var P:Position) ;
begin
with Workspace[CurrentWsnr] do
begin
while not ((Buffer^[P.Index] in WordSeparators) or
(P.Index = BufferSize)) do
begin
Inc (P.Colnr) ;
Inc (P.Index) ;
end ;
while (Buffer^[P.Index] in WordSeparators) and
(P.Index < BufferSize) do
begin
if Buffer^[P.Index] = CR
then begin
Inc (P.Linenr) ;
if Buffer^[P.Index+1] = LF
then P.Colnr := 0
else P.Colnr := 1 ;
end
else Inc (P.Colnr) ;
Inc (P.Index) ;
end ;
end ;
end ;
{-----------------------------------------------------------------------------}
{ Skips P upward until the beginning of the previous word in the text. }
{-----------------------------------------------------------------------------}
procedure WordUp (var P:Position) ;
begin
with Workspace[CurrentWsnr] do
begin
if P.Index > 1
then begin
repeat Dec (P.Index) ;
if Buffer^[P.Index] = CR
then Dec (P.Linenr) ;
until ((not (Buffer^[P.Index] in WordSeparators)) or
(P.Index = 1)) ;
while ((not (Buffer^[P.Index] in WordSeparators)) and
(P.Index > 0)) do
begin
Dec (P.Index) ;
end ;
Inc (P.Index) ;
CalculateColnr (P) ;
end ;
end ;
end ;
{-----------------------------------------------------------------------------}
{ Skips P downward to the first column of the next line. }
{ If the end of the buffer is reached, the procedure stops. }
{-----------------------------------------------------------------------------}
procedure LineDown (var P:Position) ;
var StartIndex : word ;
begin
StartIndex := P.Index ;
with Workspace[CurrentWsnr] do
begin
while (Buffer^[P.Index] <> CR) and (P.Index < BufferSize) do
Inc (P.Index) ;
if (Buffer^[P.Index] = CR)
then begin
Inc (P.Index) ;
if Buffer^[P.Index] = LF
then Inc (P.Index) ;
P.Colnr := 1 ;
Inc (P.Linenr) ;
end
else Inc (P.Colnr,P.Index-StartIndex) ;
end ;
end ;
{-----------------------------------------------------------------------------}
{ Skips P upward to the first column of the previous line. }
{ If the start of the buffer is reached, the procedure stops. }
{-----------------------------------------------------------------------------}
procedure LineUp (var P:Position) ;
begin
if P.Linenr = 1
then Dec (P.Index,P.Colnr-1)
else with workspace[CurrentWsnr] do
begin
{ go past carriage return at star